package binarytree;

public class LemonadeChange {
    public boolean lemonadeChange(int[] bills) {
        int num5 = 0, num10 = 0;
        boolean res=false;
        if (bills[0] != 5)
            return res;

        for (int i = 0; i < bills.length; i++) {
            if (bills[i] == 5) {
                num5++;
            }
            if(num5<0 || num10<0) {
                res=false;
                break;
            }
            if (bills[i] == 10) {
                num5--;
                num10++;
            }
            if (bills[i]==20){
                if (num10>0){
                    num10--;
                    num5--;
                }else{
                    num5-=3;
                }
            }
        }
        if (num5>=0 && num10>=0) res=true;
        return res;
    }
}
